#include <cstdio>
#include <algorithm>
using namespace std;
long long a,b,x,y;
int main(void){
    scanf("%I64d%I64d%I64d%I64d",&a,&b,&x,&y);
    long long ans=__gcd(x,y);
    printf("%I64d\n",min(a/(x/ans),b/(y/ans)));
    return 0;
}